import { defineStore } from "pinia";
import axios from "axios";
import {reactive} from "vue";

export const useStore = defineStore('general', {
    state: () => {
        return {
            //用户信息
            user: {
                id: -1,
                username: '',
                email: '',
                role: '',
                avatar: null,
                registerTime: null
            },
            //论坛信息
            forum: {
                types: []
            },
            //钱包信息
            wallet:{
                connected: false,
                address:'',
                tokenIds:[],
                tokenURI:[],
                metadata:[],
                balance: 0,

                nft:[],
                cusdt:0

            }
        }
    }, getters: {
        avatarUrl() {
            if(this.user.avatar)
                return `${axios.defaults.baseURL}/images${this.user.avatar}`
            else
                return 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
        }
    }, actions: {
        findTypeById(id) {
            for (let type of this.forum.types) {
                if(type.id === id)
                    return type
            }
        },
        avatarUserUrl(avatar) {
            if(avatar)
                return `${axios.defaults.baseURL}/images${avatar}`
            else
                return 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
        }
    }
})
